import java.io.IOException;

import org.kwis.msp.lcdui.Jlet;
import org.kwis.msp.lcdui.Display;
import org.kwis.msp.lcdui.Image   ;

import org.kwis.msp.lwc.ShellComponent;
import org.kwis.msp.lwc.CommandBarComponent   ;
import org.kwis.msp.lwc.Command   ;
import org.kwis.msp.lwc.CommandListener;
import org.kwis.msp.lwc.LabelComponent;


public class CommandBarEx2 extends Jlet{

	Display displayLCD ;
		
	private static  class CommandListenerHandler implements CommandListener{

		public void commandAction(Command cmd , int type , Object obj){

			ShellComponent shell = (ShellComponent)obj;

			LabelComponent labelOK = new LabelComponent(cmd.getString(), cmd.getActiveImage());
			LabelComponent labelOKTitle = new LabelComponent("OK Button Pressed");
			LabelComponent labelDIR = new LabelComponent(cmd.getString(), cmd.getActiveImage());
			LabelComponent labelDIRTitle = new LabelComponent("Dir. Butten Pressed");

			if(type==CommandListener.SELECT){
				shell.setTitle(labelOKTitle);
				shell.setWorkComponent(labelOK);
			}



			if(type==CommandListener.FOCUS_CHANGE){
				shell.setTitle(labelDIRTitle);
				shell.setWorkComponent(labelDIR);
			}

		}

	}


	public CommandBarEx2(){     }

	protected void startApp(String[] arg0){

		
		
		displayLCD = Display.getDefaultDisplay();
		ShellComponent shell = new ShellComponent();

		Image imgCMD1 = null;
		Image imgCMD2 = null;
		Image imgCMD3 = null;

		Image imgCMD1_Active = null;
		Image imgCMD2_Active = null;
		Image imgCMD3_Active = null;

		try {
			imgCMD1 = Image.createImage("/house.gif");
			imgCMD2 = Image.createImage("/friend.gif");
			imgCMD3 = Image.createImage("/telephone.gif");
			imgCMD1_Active = Image.createImage("/house2.gif");
			imgCMD2_Active = Image.createImage("/friend2.gif");
			imgCMD3_Active = Image.createImage("/telephone2.gif");

		} catch (IOException e) {
			System.out.println(e);
		}

		CommandBarComponent cmdBar = new CommandBarComponent();
		Command cmd1 = new Command("주택정보",imgCMD1,imgCMD1_Active, null);
		Command cmd2 = new Command("친구찾기",imgCMD2, imgCMD2_Active, null);
		Command cmd3 = new Command("전화번호 검색" , imgCMD3,imgCMD3_Active, null);

		cmdBar.addCommand(cmd1);
		cmdBar.addCommand(cmd2);
		cmdBar.addCommand(cmd3);

		cmdBar.setActiveIndex(0);

		cmdBar.setCommandListener(new CommandListenerHandler() , shell );

		shell.setCommand(cmdBar,false);
		displayLCD.pushCard(shell.getCard());
		
	
	}

	protected void destroyApp(boolean arg0) {

	}


}
